package cn.btks.commonserver.valid;

import cn.btks.commonserver.valid.impl.LengthValidImpl;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Created by zhangjing on 2019/12/13.
 * 长度校验自定义注解
 * 计算字符串的字节长度，编码方式为"GBK"，即1个汉字2个字节
 * 另外：编码方式为"UTF-8"为3个字节，"ISO8859-1"、"GB2312"为2个字节
 */
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {LengthValidImpl.class})
public @interface LengthValid {

    int byteCount() default 0;

    String decoding() default "GBK";

    String message() default "超出要求范围";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
